cmake_minimum_required(VERSION 3.10)
project(EconCore VERSION 1.0.0 LANGUAGES CXX)

# 版本信息
set(ECONCORE_VERSION ${PROJECT_VERSION})
set(ECONCORE_SOVERSION 1)

# 编译标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# 警告设置
if(MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX")
else()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Werror")
endif()

# 依赖项
find_package(OpenMP REQUIRED)

# 包含目录
include_directories(include)

# 库目标
add_library(EconCore SHARED src/EconCore.cpp)

target_link_libraries(EconCore PUBLIC OpenMP::OpenMP_CXX)

set_target_properties(EconCore PROPERTIES
    VERSION ${ECONCORE_VERSION}
    SOVERSION ${ECONCORE_SOVERSION}
    POSITION_INDEPENDENT_CODE ON
    CXX_VISIBILITY_PRESET hidden
    VISIBILITY_INLINES_HIDDEN ON
)

# 经济计算特定优化
if(MSVC)
    target_compile_options(EconCore PRIVATE /O2 /fp:fast /arch:AVX2)
else()
    target_compile_options(EconCore PRIVATE 
        -O3 -march=native -ffast-math -mavx2 -mfma
    )
endif()

# 安装规则
install(TARGETS EconCore
    EXPORT EconCoreTargets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
    INCLUDES DESTINATION include
)

install(DIRECTORY include/ DESTINATION include)

# 导出目标
install(EXPORT EconCoreTargets
    FILE EconCoreTargets.cmake
    NAMESPACE EconCore::
    DESTINATION lib/cmake/EconCore
)

# 测试支持
option(BUILD_TESTING "Build tests" ON)
if(BUILD_TESTING)
    enable_testing()
    add_subdirectory(tests)
endif()

# 跨模块依赖
find_package(AgentCore REQUIRED)
target_link_libraries(EconCore PRIVATE AgentCore::AgentCore)